/*
 * @Author       : NaN 353362604@qq.com
 * @Date         : 2023-04-23 13:34:36
 * @LastEditTime : 2023-06-21 16:02:16
 * @LastEditors  : NaN 353362604@qq.com
 * @FilePath     : \AdminStration\src\Pages\Admin\PageType\Home.jsx
 * @Description  :
 */
import '../Scss/Home.scss'
import { useRequest } from 'ahooks'
import { useEffect, useState } from 'react'
import { Http } from '../../../Common/Api'
import { TemplateData } from '../../../Common/Router/MenuNav/DiyList/WebHomeSetUp'

const Home = () => {
    const { runAsync } = useRequest(Http, { manual: true })
    const [HomeData, setHomeData] = useState()

    useEffect(() => {
        const [uuid] = Object.keys(JSON.parse(localStorage.getItem('ClientData')).project)
        runAsync({ url: 'getJsonInfoByUuid', data: { uuid: `home${uuid}` } }).then(res => setHomeData(res))
    }, [runAsync])

    return (
        <div className="HomeAdmin">
            {HomeData &&
                HomeData.map(({ i, w, h, x, y }) => {
                    const Template = TemplateData[i]
                    const style = { gridArea: `${y + 1} / ${x + 1} / ${y + h + 1} / ${w + x + 1}` }
                    return (
                        <div key={i} style={style}>
                            <Template />
                        </div>
                    )
                })}
        </div>
    )
}

export default Home
